<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.model.core.ContentField" scope="page" var="LINE_TYPE" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="CONTENT_FIELD_VALUE_KEY" scope="page" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="OWNER_INFO_KEY" scope="page" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="CONTENT_FIELD_KEY" scope="page" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="REDIRECT_URL_KEY" scope="page" />

<c:set var="contentField" value="${sessionScope[pageScope.CONTENT_FIELD_KEY]}" />

<c:set var="redirectUrl" value="${sessionScope[pageScope.REDIRECT_URL_KEY]}" />
<c:set var="redirectUrlPresents" value="${redirectUrl != null && redirectUrl != ''}" />

<c:set var="contentFieldType" value="${contentField.type}" />
<c:set var="showIframe" value="true" />
<c:set var="colspan" value="2" />
<c:if test="${contentFieldType == pageScope.LINE_TYPE}">
	<c:set var="showIframe" value="false" />
	<c:set var="colspan" value="1" />
</c:if>
<atleap:content identifier="information" ignore="true" />
<table cellpadding="0" cellspacing="0" border="0" class="modificationTable">
	<tr>
		<th><atleap:message key="core.contentFieldValue.form.contentFieldOwnerInfo" /></th>
		<td>${sessionScope[pageScope.OWNER_INFO_KEY]}</td>
	</tr>
	<tr>
		<th><atleap:message key="core.contentFieldValue.form.contentFieldIdentifier" /></th>
		<td><c:out value="${contentField.identifier}" escapeXml="true" /></td>
	</tr>
</table>
<atleap:iterator items="${requestScope.contentFieldValues}" var="entry">
	<c:set var="contentLocale" value="${entry.key}" />
	<c:set var="contentFieldValue" value="${entry.value}" />
	<table cellpadding="0" cellspacing="0" width="100%" border="0" class="tableView">
		<tr>
			<th align="left" width="50%"><atleap:message key="core.contentFieldValue.form.language" /></th>
			<td>
				<atleap:fieldValue valueMap="${contentLocale.title}" var="languageTitle" />
				<c:if test="${empty languageTitle}">
					<c:set var="languageTitle" value="${contentLocale.identifier}" />
				</c:if>
				${languageTitle}
			</td>
		</tr>
		<tr>
			<th align="left" width="50%"><atleap:message key="core.contentFieldValue.form.lastUpdatedDatetime" /></th>
			<td><atleap:formatDate value="${contentFieldValue.lastUpdatedDatetime}" type="datetime" /></td>
		</tr>
		<tr>
			<th colspan="${colspan}" align="left"><atleap:message key="core.contentFieldValue.form.value" /></th>
			<c:if test="${!showIframe}">
				<td>${requestScope[pageScope.CONTENT_FIELD_VALUE_KEY][contentFieldValue.id]}</td>
			</c:if>
		</tr>
	</table>

	<c:if test="${showIframe}">
		<atleap:iframe width="100%" height="400" src="${ctxPath}/blank.html">
			${requestScope[pageScope.CONTENT_FIELD_VALUE_KEY][contentFieldValue.id]}
		</atleap:iframe>
	</c:if>

	<atleap:form action="core/contentFieldValue/callCreateOrUpdate" method="GET" validateOnSubmit="false">
        <html:hidden property="locale" value="${contentLocale.identifier}" />
        <atleap:isUserInRole roles="core-contentFieldValue-createOrUpdate">
            <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.callUpdate" /></atleap:submit>
        </atleap:isUserInRole>
        <html:hidden property="contentFieldId" value="${contentFieldValue.contentField.id}" />
        <atleap:cancel styleClass="button">
            <c:choose>
                <c:when test="${redirectUrlPresents}">
                    <atleap:message key="core.commons.buttons.back" />
                </c:when>
                <c:otherwise>
                    <atleap:message key="core.commons.buttons.showList" />
                </c:otherwise>
            </c:choose>
        </atleap:cancel>
	</atleap:form>
	<br />
</atleap:iterator>
